home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / systracker_src / src / st_libs.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-28  |  3.1 KB  |  122 lines

  1. /***************************************************************************/
  2. /* st_libs.c - Amiga shared library handling.                              */
  3. /*                                                                         */
  4. /* Copyright © 1999-2000 Andrew Bell. All rights reserved.                 */
  5. /***************************************************************************/
  6.  
  7. #include "SysTracker_rev.h"
  8. #include "st_include.h"
  9. #include "st_protos.h"
  10. #include "st_strings.h"
  11.  
  12. /***************************************************************************/
  13. /* Data and defines */
  14. /***************************************************************************/
  15.  
  16. struct Library *IntuitionBase = NULL;
  17. struct Library *UtilityBase = NULL;
  18. struct Library *WorkbenchBase = NULL;
  19. struct Library *DiskFontBase = NULL;
  20. struct Library *GfxBase = NULL;
  21.  
  22. #define MIN_OS_VER 39L
  23.  
  24. struct GetLibs GetLibsData[] =
  25. {
  26.   { "intuition.library", MIN_OS_VER, &IntuitionBase, GL_ABSOLUTE },
  27.   { "utility.library",   MIN_OS_VER, &UtilityBase,   GL_ABSOLUTE },
  28.   { "workbench.library", MIN_OS_VER, &WorkbenchBase, GL_ABSOLUTE },
  29.   { "diskfont.library",  MIN_OS_VER, &DiskFontBase,  GL_ABSOLUTE },
  30.   { "graphics.library",  MIN_OS_VER, &GfxBase,       GL_ABSOLUTE },
  31.   { NULL,                0,          NULL,           0           }, 
  32. };
  33.  
  34. /***************************************************************************/
  35.  
  36. GPROTO BOOL LIBS_Init( void )
  37. {
  38.   /*********************************************************************
  39.    *
  40.    * LIBS_Init()
  41.    *
  42.    * Open all of the system libraries that SysTracker requires.
  43.    *
  44.    *********************************************************************
  45.    *
  46.    */
  47.  
  48.   register struct GetLibs *GLD = GetLibsData;
  49.   register BOOL OLFailure = FALSE;
  50.  
  51.   if (!GUI_InitMUI()) return FALSE;
  52.  
  53.   while(GLD->gl_Name)
  54.   {
  55.     if (!(*GLD->gl_LibBasePtr =
  56.       OpenLibrary(GLD->gl_Name, (LONG) GLD->gl_Version)))
  57.     {
  58.       if (GLD->gl_Mode == GL_ABSOLUTE) OLFailure = TRUE;
  59.     }
  60.     GLD++;
  61.   }
  62.  
  63.   if (OLFailure)
  64.   {
  65.     if (IntuitionBase)
  66.     {
  67.       UBYTE TmpStr[128];
  68.       register UBYTE *ErrStr = MEM_AllocVec(1024);    
  69.  
  70.       if (ErrStr)
  71.       {
  72.         strcpy(ErrStr, STR_Get(SID_CANNOT_OPEN_FOLLOWING_LIBS));
  73.  
  74.         GLD = GetLibsData;
  75.  
  76.         while(GLD->gl_Name)
  77.         {
  78.           if ((*GLD->gl_LibBasePtr == NULL) &&
  79.               (GLD->gl_Mode == GL_ABSOLUTE))
  80.           {
  81.             sprintf(TmpStr, STR_Get(SID_LIB_VERSION_FMT),
  82.               GLD->gl_Name, GLD->gl_Version);
  83.             strcat(ErrStr, TmpStr);
  84.           }           
  85.           GLD++;
  86.         }
  87.         M_PrgError(ErrStr, NULL);
  88.         MEM_FreeVec(ErrStr);
  89.       } 
  90.     }
  91.     return FALSE;
  92.   } 
  93.   return TRUE;
  94. }
  95.  
  96. GPROTO void LIBS_Free( void )
  97. {
  98.   /*********************************************************************
  99.    *
  100.    * LIBS_Free()
  101.    *
  102.    * Close all system libraries opened by LIBS_Init().
  103.    *
  104.    *********************************************************************
  105.    *
  106.    */
  107.  
  108.   register struct GetLibs *GLD = GetLibsData;
  109.  
  110.   while(GLD->gl_Name)
  111.   {
  112.     if (*GLD->gl_LibBasePtr)
  113.     {
  114.       CloseLibrary(*GLD->gl_LibBasePtr); *GLD->gl_LibBasePtr = NULL;
  115.     }
  116.     GLD++;
  117.   }
  118.   GUI_EndMUI();
  119. }
  120.  
  121.  
  122.